<?php

namespace app\common\model;

use app\common\model\BaseModel as BaseModel;
use ShidianUtil\Thinkphp\Facade\HumanizedTool;
use ShidianUtil\Utils\TimeUtil;

/**
 * Class LawsuitComment
 * @package app\common\model
 * @property int $id
 * @property int $categoryId
 * @property string $showName
 * @property string $headImgUrl
 * @property string $comment
 * @property int $updated
 * @property int $created
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037579
 * @link https://www.kancloud.cn/manual/think-orm/1257998
 * @link https://www.kancloud.cn/thinkphp/master-database-and-model/265551
 */
class LawsuitComment extends BaseModel
{
    protected $name = 'LawsuitComment';

    public function getHeadImgAttr($value, $data)
    {
        $headImgUrl = $data['headImgUrl'] ?? null;
        if (is_blank($headImgUrl)) {
            $headImgUrl = '/storage/static/images/member/touxiang.png';
        }
        return image_url($headImgUrl);
    }

    public function getTimeStrAttr($value, $data)
    {
        $now = time();
        $time = $data['created'] ?? $now;

        // 把时间调整到今天
        $time -= TimeUtil::stamp(TimeUtil::DAY, $time);
        $time += TimeUtil::stamp(TimeUtil::DAY, $now);

        if($time > $now){
            $time = $now;
        }

        return HumanizedTool::time($time);
    }

    /**
     * 1对1
     * @return \think\model\relation\HasOne
     */
    //    public function one(){
    //        return $this->hasOne( Test1::class, 'Test1表中的键', 'LawsuitComment表中的键');
    //    }

    /**
     * 1对多
     * @return \think\model\relation\HasMany
     */
    //    public function many(){
    //        return $this->hasMany( Test1::class, 'Test1表中的键', 'LawsuitComment表中的键');
    //    }

    /**
     * 多对多
     * @return \think\model\relation\BelongsToMany
     */
    //    public function belongs(){
    //        return $this->belongsToMany( Test1::class, '中间表', '中间表中Test1的键', '中间表中LawsuitComment的键');
    //    }
}
